<template>
  <div>
    <global-layout @dynamicRouterShow="dynamicRouterShow">
      <contextmenu :itemList="menuItemList" :visible.sync="menuVisible" @select="onMenuSelect" />
      <a-tabs
        @contextmenu.native="e => onContextmenu(e)"
        v-if="multipage"
        :active-key="activePage"
        class="tab-layout-tabs"
        style="height:52px"
        :hide-add="true"
        type="editable-card"
        @change="changePage"
        @edit="editPage"
      >
        <a-tab-pane :id="page.fullPath" :key="page.fullPath" v-for="page in pageList">
          <span slot="tab" :pagekey="page.fullPath">{{ page.meta.title }}</span>
        </a-tab-pane>
      </a-tabs>
      <div class="namelist">
        <div class="namelist-inner">
          <div class="namelist-inner-top">
            <router-link to="/knowledgeBase/diseaseKnowledge" style="color: #38C3C8;">
              <span class="span">
                <img src="../../assets/images/fan hui.png" class="img" />
                &nbsp;&nbsp;返回
              </span>
            </router-link>
            <span class="namelist-collection span" style="color: #38C3C8;">
              <img src="../../assets/images/shou cang.png" class="img" alt />&nbsp;&nbsp;收藏
            </span>
			
            <span class="namelist-collection span" style="color: #38C3C8;width: 100px;" @click="openAll">
              <img src="../../assets/images/shou cang.png" class="img" alt />&nbsp;&nbsp;{{ openShowText }}
            </span>
          </div>
          <p>{{searchdetail.dis_name}}</p>
        </div>
      </div>
      <div class="namelist-inner-inner">
        <el-collapse v-model="activeNames" @change="handleChange" class="namelist-inner-inner-top">
          <el-row class="row" id="div0">
            <el-col :span="1" style="padding-top: 10px;">
              <p>概况</p>
            </el-col>
            <el-col :span="23" style="padding-left: 65px;padding-top: 0px;">
              <el-collapse-item name="1" class="inner-datail">
                <el-row>
                  <el-col :span="1">
                    <p>参</p>
                  </el-col>
                  <el-col :span="23">
                    <div>{{searchdetail.gen_sit}}</div>
                  </el-col>
                </el-row>
              </el-collapse-item>
            </el-col>
          </el-row>
          <el-row class="row" id="div1">
            <el-col :span="2" style="padding-top: 10px;">
              <p>临床表现</p>
            </el-col>
            <el-col :span="22">
              <el-collapse-item
                name="2"
                class="inner-datail"
                style="padding-left: 20px;padding-top: 0px;"
              >
                <el-row>
                  <el-col :span="1">
                    <p>参</p>
                  </el-col>
                  <el-col :span="23">
                    <div>{{searchdetail.cli_man}}</div>
                  </el-col>
                </el-row>
              </el-collapse-item>
            </el-col>
          </el-row>
          <el-row class="row" id="div2">
            <el-col :span="1" style="padding-top: 10px;">
              <p>病因</p>
            </el-col>
            <el-col :span="23" style="padding-left: 65px;padding-top: 0px;">
              <el-collapse-item name="3" class="inner-datail">
                <el-row>
                  <el-col :span="1">
                    <p>参</p>
                  </el-col>
                  <el-col :span="23">
                    <div>{{searchdetail.cau_dis}}</div>
                  </el-col>
                </el-row>
              </el-collapse-item>
            </el-col>
          </el-row>
          <el-row class="row" id="div3">
            <el-col :span="1" style="padding-top: 10px;">
              <p>检查</p>
            </el-col>
            <el-col :span="23">
              <el-collapse-item
                name="4"
                class="inner-datail"
                style="padding-left: 65px;padding-top: 0px;"
              >
                <el-row>
                  <el-col :span="1">
                    <p>参</p>
                  </el-col>
                  <el-col :span="23">
                    <div>{{searchdetail.check_up}}</div>
                  </el-col>
                </el-row>
              </el-collapse-item>
            </el-col>
          </el-row>
          <el-row class="row">
            <el-col :span="1" style="padding-top: 10px;">
              <p>诊断</p>
            </el-col>
            <el-col :span="23">
              <el-collapse-item
                name="5"
                class="inner-datail"
                style="padding-left: 65px;padding-top: 0px;"
              >
                <el-row>
                  <el-col :span="1">
                    <p>参</p>
                  </el-col>
                  <el-col :span="23">
                    <div>{{searchdetail.diagonse}}</div>
                  </el-col>
                </el-row>
              </el-collapse-item>
            </el-col>
          </el-row>
          <el-row class="row">
            <el-col :span="1" style="padding-top: 10px;">
              <p>治疗</p>
            </el-col>
            <el-col :span="23">
              <el-collapse-item
                name="7"
                class="inner-datail"
                style="padding-left: 65px;padding-top: 0px;"
              >
                <el-row>
                  <el-col :span="1">
                    <p>参</p>
                  </el-col>
                  <el-col :span="23">
                    <div>{{searchdetail.treat}}</div>
                  </el-col>
                </el-row>
              </el-collapse-item>
            </el-col>
          </el-row>
        </el-collapse>
      </div>
      <company-profile />
    </global-layout>
    <div class="container">
      <div class="nav" :class="[isSelected]">
        <span class="navon5"></span>
        <p class="navon4"></p>
        <li>
          <p href class="navon0"></p>
          <p href class="navon0-1"></p>
          <a id="navon0" href="#div0" @click="navClick">概况</a>
        </li>
        <li>
          <p href class="navon1"></p>
          <p href class="navon1-1"></p>
          <a id="navon1" href="#div1" @click="navClick">临床表现</a>
        </li>
        <li>
          <p href class="navon2"></p>
          <p href class="navon2-1"></p>
          <a id="navon2" href="#div2" @click="navClick">病因</a>
        </li>
        <li>
          <p href class="navon3"></p>
          <p href class="navon3-1"></p>
          <a id="navon3" href="#div3" @click="navClick">检查</a>
        </li>
      </div>
    </div>
  </div>
</template>

<script>
import GlobalLayout from '@/components/page/GlobalLayout'
import Contextmenu from '@/components/menu/Contextmenu'
import { mixin, mixinDevice } from '@/utils/mixin.js'
import CompanyProfile from '../../components/knowlage/companyProfile'
import { JeecgListMixin } from '@/mixins/zkxhKnowledge'
import { getAction } from '@/api/manage'

const indexKey = '/dashboard/analysis'

export default {
  //这是主页
  name: 'DiseaseKnowledge',
  components: {
    GlobalLayout,
    Contextmenu,
    CompanyProfile
  },
  mixins: [mixin, mixinDevice, JeecgListMixin],
  data() {
    return {
      pageList: [],
      linkList: [],
      activeNames: ['1'],
      isSelected: '',
      searchdetail: [],
      url: {
        searchDetail: '/es/searchFull/getSearchSecondLeveList'
      },
      isOpenAll: false,//记录是否所有的都处于打开/关闭状态
      openShowText: "全部展开",//记录按钮文字
      activePage: '',
      text: `A dog is a type of domesticated animal.Known for its loyalty and faithfulness,it can be found as a welcome guest in many households across the world.`,
      menuVisible: false,
      menuItemList: [
        { key: '1', icon: 'arrow-left', text: '关闭左侧' },
        { key: '2', icon: 'arrow-right', text: '关闭右侧' },
        { key: '3', icon: 'close', text: '关闭其它' }
      ],
      url: {
        list: '/knowledge/knoCgOwner/getDepAll',
        listseach: '/knowledge/knoCgOwner/list',
        fuzzysearch: '/es/searchFull/getSearchDiseaseOrDrugsAll',
        getSearchSecondLeveList: '/es/searchFull/getSearchSecondLeveList',
        searchDetail: '/es/searchFull/getSearchSecondLeveList'
      }
    }
  },
  computed: {
    multipage() {
      //判断如果是手机模式，自动切换为单页面模式
      if (this.isMobile()) {
        return false
      } else {
        return this.$store.state.app.multipage
      }
    }
  },
  created() {
    this.everyId = this.$route.params.id
    getAction(this.url.searchDetail, { searchId: this.everyId, searchType: 1 }).then(res => {
      if (res.success) {
        console.log('132456')
        this.searchdetail = res.result[0]
        console.log(this.searchdetail)
      }
      if (res.code === 510) {
        this.$message.warning(res.message)
      }
      this.loading = false
    })

    if (this.$route.path != indexKey) {
      this.pageList.push({
        name: 'dashboard-analysis',
        path: indexKey,
        fullPath: indexKey,
        meta: {
          icon: 'dashboard',
          title: '首页'
        }
      })
      this.linkList.push(indexKey)
    }
    this.pageList.push(this.$route)
    this.linkList.push(this.$route.fullPath)
    this.activePage = this.$route.fullPath
  },
  watch: {
    $route: function(newRoute) {
      this.activePage = newRoute.fullPath
      if (!this.multipage) {
        this.linkList = [newRoute.fullPath]
        this.pageList = [Object.assign({}, newRoute)]
      } else if (this.linkList.indexOf(newRoute.fullPath) < 0) {
        this.linkList.push(newRoute.fullPath)
        this.pageList.push(Object.assign({}, newRoute))
      } else if (this.linkList.indexOf(newRoute.fullPath) >= 0) {
        let oldIndex = this.linkList.indexOf(newRoute.fullPath)
        let oldPositionRoute = this.pageList[oldIndex]
        this.pageList.splice(oldIndex, 1, Object.assign({}, newRoute, { meta: oldPositionRoute.meta }))
      }
    },
    activePage: function(key) {
      let index = this.linkList.lastIndexOf(key)
      let waitRouter = this.pageList[index]
      this.$router.push(Object.assign({}, waitRouter))
    },
    multipage: function(newVal) {
      if (!newVal) {
        this.linkList = [this.$route.fullPath]
        this.pageList = [this.$route]
      }
    }
  },
  methods: {
	openAll(){
	    if(this.isOpenAll){
	      this.activeNames = [];
	      this.openShowText = "全部展开";
	    }else{
	      this.openShowText = "全部关闭";
	      this.activeNames = ['1','2','3','4','5'];
	    }
	    this.isOpenAll = !this.isOpenAll;
	},
    navClick(e) {
      var scrollBox1 = document.querySelector('.container')
      scrollBox1.scrollTo(0, [...e.target.id].pop() * 500)
      this.isSelected = e.target.id + '-selected'
      console.log(e.target.id)
      document.querySelector('#navon0').style.color = '#ccc'
      document.querySelector('#navon1').style.color = '#ccc'
      document.querySelector('#navon2').style.color = '#ccc'
      document.querySelector('#navon3').style.color = '#ccc'
      document.querySelector('.navon0').style.backgroundColor = '#ccc'
      document.querySelector('.navon1').style.backgroundColor = '#ccc'
      document.querySelector('.navon2').style.backgroundColor = '#ccc'
      document.querySelector('.navon3').style.backgroundColor = '#ccc'
      document.querySelector('.' + e.target.id).style.backgroundColor = '#38c3c8'
      document.querySelector('#' + e.target.id).style.color = '#38c3c8'
    },
    //这是可删减顶部导航页面
    changePage(key) {
      this.activePage = key
    },
    editPage(key, action) {
      this[action](key)
    },
    remove(key) {
      if (key == indexKey) {
        this.$message.warning('首页不能关闭!')
        return
      }
      if (this.pageList.length === 1) {
        this.$message.warning('这是最后一页，不能再关闭了啦')
        return
      }
      this.pageList = this.pageList.filter(item => item.fullPath !== key)
      let index = this.linkList.indexOf(key)
      this.linkList = this.linkList.filter(item => item !== key)
      index = index >= this.linkList.length ? this.linkList.length - 1 : index
      this.activePage = this.linkList[index]
    },
    onContextmenu(e) {
      const pagekey = this.getPageKey(e.target)
      if (pagekey !== null) {
        e.preventDefault()
        this.menuVisible = true
      }
    },
    getPageKey(target, depth) {
      depth = depth || 0
      if (depth > 2) {
        return null
      }
      let pageKey = target.getAttribute('pagekey')
      pageKey = pageKey || (target.previousElementSibling ? target.previousElementSibling.getAttribute('pagekey') : null)
      return pageKey || (target.firstElementChild ? this.getPageKey(target.firstElementChild, ++depth) : null)
    },
    onMenuSelect(key, target) {
      let pageKey = this.getPageKey(target)
      switch (key) {
        case '1':
          this.closeLeft(pageKey)
          break
        case '2':
          this.closeRight(pageKey)
          break
        case '3':
          this.closeOthers(pageKey)
          break
        default:
          break
      }
    },
    closeOthers(pageKey) {
      let index = this.linkList.indexOf(pageKey)
      if (pageKey == indexKey) {
        this.linkList = this.linkList.slice(index, index + 1)
        this.pageList = this.pageList.slice(index, index + 1)
        this.activePage = this.linkList[0]
      } else {
        let indexContent = this.pageList.slice(0, 1)[0]
        this.linkList = this.linkList.slice(index, index + 1)
        this.pageList = this.pageList.slice(index, index + 1)
        this.linkList.unshift(indexKey)
        this.pageList.unshift(indexContent)
        this.activePage = this.linkList[1]
      }
    },
    closeLeft(pageKey) {
      if (pageKey == indexKey) {
        return
      }
      let tempList = [...this.pageList]
      let indexContent = tempList.slice(0, 1)[0]
      let index = this.linkList.indexOf(pageKey)
      this.linkList = this.linkList.slice(index)
      this.pageList = this.pageList.slice(index)
      this.linkList.unshift(indexKey)
      this.pageList.unshift(indexContent)
      if (this.linkList.indexOf(this.activePage) < 0) {
        this.activePage = this.linkList[0]
      }
    },
    closeRight(pageKey) {
      let index = this.linkList.indexOf(pageKey)
      this.linkList = this.linkList.slice(0, index + 1)
      this.pageList = this.pageList.slice(0, index + 1)
      if (this.linkList.indexOf(this.activePage < 0)) {
        this.activePage = this.linkList[this.linkList.length - 1]
      }
    },
    changeActivekey(key) {
      console.log(key)
    },
    handleChange(val) {
      console.log(val)
    },

    //update-begin-author:taoyan date:20190430 for:动态路由title显示配置的菜单title而不是其对应路由的title
    dynamicRouterShow(key, title) {
      let keyIndex = this.linkList.indexOf(key)
      if (keyIndex >= 0) {
        let currRouter = this.pageList[keyIndex]
        let meta = Object.assign({}, currRouter.meta, { title: title })
        this.pageList.splice(keyIndex, 1, Object.assign({}, currRouter, { meta: meta }))
      }
    }
    //update-end-author:taoyan date:20190430 for:动态路由title显示配置的菜单title而不是其对应路由的title
  }
}
</script>

<style lang="scss">
/*
 * The following styles are auto-applied to elements with
 * transition="page-transition" when their visibility is toggled
 * by Vue.js.
 *
 * You can easily play with the page transition by editing
 * these styles.
 */

.page-transition-enter {
  opacity: 0;
}

.page-transition-leave-active {
  opacity: 0;
}

.page-transition-enter .page-transition-container,
.page-transition-leave-active .page-transition-container {
  -webkit-transform: scale(1.1);
  transform: scale(1.1);
}

/*美化弹出Tab样式*/
.ant-tabs-nav-container {
  margin-top: 4px;
}

/* 修改 ant-tabs 样式 */
.tab-layout-tabs.ant-tabs {
  border-bottom: 1px solid #ccc;
  border-left: 1px solid #ccc;
  background-color: white;
  padding: 0 20px;

  .ant-tabs-bar {
    margin: 4px 0 0;
    border: none;
  }
}

.ant-tabs {
  &.ant-tabs-card .ant-tabs-tab {
    padding: 0 24px !important;
    background-color: white !important;
    margin-right: 10px !important;

    .ant-tabs-close-x {
      width: 12px !important;
      height: 12px !important;
      opacity: 0 !important;
      cursor: pointer !important;
      font-size: 12px !important;
      margin: 0 !important;
      position: absolute;
      top: 36%;
      right: 6px;
    }

    &:hover .ant-tabs-close-x {
      opacity: 1 !important;
    }
  }
}

.ant-tabs.ant-tabs-card > .ant-tabs-bar {
  .ant-tabs-tab {
    border: none !important;
    border-bottom: 1px solid transparent !important;
  }
  .ant-tabs-tab-active {
    border-color: #13c2c2 !important;
  }
}
.namelist {
  background-color: #fff;
  width: 100%;
  padding-top: 24px;
  padding-left: 32px;
  padding-bottom: 20px;

  div {
    border: none;
    background-color: #fff;
    width: 1100px;
  }

  .namelist-inner {
    width: 1124px;
    border: 1px #ebeef5 solid;
    border-bottom: none;
    background-color: #fff;
    height: 100%;

    .namelist-inner-top {
      float: left;
      height: 100%;
      width: 100%;

      .span {
        width: 76px;
        height: 32px;
        border: 1px #c9eff1 solid;
        background-color: #ebf9fa;
        text-align: center;
        line-height: 32px;
        border-radius: 4px;
        margin-left: 0px;
        float: left;
        margin-left: 32px;
        margin-top: 24px;
      }
      .namelist-collection {
        float: right;
        margin-right: 32px;

        .img {
          margin-top: -3px;
        }
      }
    }

    p {
      margin-top: 14px;
      font-size: 24px;
      color: #333333;
      float: left;
      margin-left: 32px;
      margin-top: 18px;
      padding-bottom: 10px;
    }
  }
}
.namelist-inner-inner {
  background-color: #fff;
  margin-left: 12px;
  padding-left: 32px;
  margin-top: -40px;
  padding-bottom: 20px;

  .namelist-inner-inner-top {
    border: 1px #ebeef5 solid;
    width: 1124px;
    padding-left: 32px;
    background-color: #fff;

    p {
      font-size: 18px;
      color: #333;
    }

    .inner-datail {
      margin-top: 0px;
      p {
        font-size: 14px;
        width: 16px;
        height: 16px;
        background-color: #38c3c8;
        line-height: 16px;
        text-align: center;
        margin-top: 6px;
        border-radius: 2px;
        color: #fff;
      }
      span {
        color: #666;
      }
    }
  }
}
.el-icon-arrow-right:before {
  content: '\E6E0';
}
.el-icon-arrow-right.is-active:before {
  content: '\E6E0';
}
.container {
  position: absolute;
  top: 300px;
  right: 300px;
  display: flex;
  height: 120px;

  .nav {
    position: fixed;
    z-index: 5;
    display: inline-flex;
    flex-wrap: wrap;
    width: 100px;
    height: inherit;

    .navon4 {
      width: 8px;
      height: 8px;
      background-color: #fff;
      border-radius: 4px;
      border: 2px #ccc solid;
      position: relative;
      top: 5px;
      left: -5px;
    }

    li {
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
      left: 0;
      width: 100%;
      padding-top: 3px;

      .navon0-1 {
        height: 10px;
        width: 2px;
        background-color: #ccc;
        position: relative;
        top: -8px;
        left: -40px;
      }
      .navon1-1 {
        height: 10px;
        width: 2px;
        background-color: #ccc;
        position: relative;
        top: -10px;
        left: -26px;
      }
      .navon2-1 {
        height: 10px;
        width: 2px;
        background-color: #ccc;
        position: relative;
        top: -8px;
        left: -40px;
      }
      .navon3-1 {
        height: 10px;
        width: 2px;
        background-color: #ccc;
        position: relative;
        top: -10px;
        left: -40px;
      }

      .navon0 {
        width: 6px;
        height: 6px;
        background-color: #ccc;
        border-radius: 50%;
        position: relative;
        top: 5px;
        left: -36px;
      }

      .navon1 {
        width: 6px;
        height: 6px;
        background-color: #ccc;
        border-radius: 50%;
        position: relative;
        top: 5px;
        left: -22px;
      }
      .navon2 {
        width: 6px;
        height: 6px;
        background-color: #ccc;
        border-radius: 50%;
        position: relative;
        top: 5px;
        left: -36px;
      }
      .navon3 {
        width: 6px;
        height: 6px;
        background-color: #ccc;
        border-radius: 50%;
        position: relative;
        top: 5px;
        left: -36px;
      }

      a {
        font-size: 14px;
        left: 0px;
        cursor: pointer;
        color: #ccc;
        padding: 0px;
        display: inline;
      }
      a:hover {
        color: #38c3c8;
      }
    }
  }
}
</style>